<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      const str = "abcd";
      let r = "";
      for (let i = 1; i <= str.length; i++) {
        if (i === 1) {
          r += str.slice(-i);
        } else {
          r += str.slice(-i, -i + 1);
        }
      }
      console.log(r);
      // console.log(str.slice(-1));
      // console.log(str.slice(-2, -2 + 1));
      // console.log(str.slice(-3, -3 + 1));
      // console.log(str.slice(-4, -4 + 1));
      // console.log(str.slice(-5, -5 + 1));
    </script>
  </body>
</html>
